﻿<section class="content-header">
    <h1>
        文章抓取
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home")"><i class="fa fa-home"></i> 首页</a></li>
        <li class="active">基础库</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-lg-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <div class="dataTable-tools btn-group">
                        @Html.Bootstrap().LinkButton("添加", ToolBarIco.Create).Href("javascript:window.app.loadUI('" + Url.Action("Create") + "')")
                        @Html.Bootstrap().LinkButton("删除", ToolBarIco.Delete).Click("window.app.deleteItem('dataTable','" + @Url.Action("Delete") + "')")
                        @Html.Bootstrap().LinkButton("刷新", ToolBarIco.Refresh).Click("window.app.search();")
                        @Html.Bootstrap().LinkButton("采集", ToolBarIco.Create).Click("work();")
                    </div>
                    <div class="box-tools">

                        <div class="input-group input-group-sm SearchArea" style="width: 150px;">
                            <input type="text" name="Name" class="form-control pull-right" placeholder="标题">

                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default" onclick="window.app.search();"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                    </div>
                    <div class="box-body no-padding">
                        <div class="table-responsive">
                            <table id="dataTable" class="table table-bordered table-striped table-hover dataTable text-center" width="100%"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<script type="text/javascript">


    $('#dataTable').dataTable({
        "serverSide": true,
        "ajax": {
            "url": "@Url.Action("GetPaged")",
            "type": "POST"
        },
        "columnDefs": [
            { "searchable": false, sortable: false, "orderable": false, "targets": [-1, 0, 1, 2] }, { "sClass": "editableCol", "aTargets": [1] }
        ],
        columns: [
            { title: '<label class="checkbox i-checks"><input type="checkbox" /><i></i></label>', data: function (row, type, set) { return '<label class="checkbox i-checks"><input type="checkbox" name="cellCheckbox" value="' + row.id + '" ' + (row.isSpider === true ? 'disabled="disabled"' : '') + ' /><i></i></label>'; }, "bStorable": false, width: 30 },
             {
                 title: "类型", data: function (row) {
                     if (row.isSpider === 0) {
                         return "<span class=\"label label-success\">采集</span>";
                     }
                     if (row.isSpider === 1) {
                         return "<span class=\"label label-danger\">爬虫</span>";
                     }
                     if (row.isSpider === 2) {
                         return "<span class=\"label label-info\">浏览器</span>";
                     }
                     return "";
                 }, width: 60, "sClass": "center"
             },
            {
                title: "采集", data: function (row) {
                    return '<a data-toggle="ajaxLoad" href="@Url.Action("Edit")/' + row.id + '">' + row.name + '</a>';
                }
            },
            {
                title: "新建节点", data: function (row) {
                    var html = '<a data-toggle="ajaxModal" href="@Url.Action("Node")/?ParentId=' + row.id + '&id=">新建节点</a>';
                    return html;
                }, width: 60, "sClass": "center"
            }
            ,
             {
                 title: "节点", data: function (row) {
                     var html = '';
                     $.each(row.children, function (index, item) {
                         html += '<a data-toggle="ajaxModal" href="@Url.Action("Node")/?Id=' + item.id + '">节点' + (index + 1) + '</a>' + "、";
                     });
                     return html;
                 }, width: 120, "sClass": "center"
             }
             ,
            { title: "采集数量", data: "articleGatherCount", width: 90, "sClass": "right" }
            ,
            { title: "启用", data: function (row) { return !row.isDisabled ? "是" : "否" }, width: 140, "sClass": "center" }
            ,
            { "title": "最后采集", data: function (row) { return new Date(row.lastWork).format("MM-dd HH:mm:ss"); }, width: 140, "sClass": "center" }
        ]
    });

    function work() {
        var ids = new Array();
        $("#dataTable").find("td input").each(function () {
            if (this.checked)
                ids.push(this.value);
        });
        if (ids.length > 0)
            window.app.loadUI("Gather/WrokConfig?ids=" + ids.join(','));
        else
            alert("请勾选。");
    }

</script>